/**
 * Created by huotaol on 2017/5/17.
 */
import React, {Component} from "react";
import PropTypes from "prop-types";
import {ListView, View} from "react-native";
import ModuleCommonHeader from "../../module/ModuleCommonHeader";
import Util from "../../Util";
import NextButton from "../common/NextButton";
import {Actions} from "react-native-router-flux";
import SwitchTextItem from "../common/SwitchTextItem";

const DATA_SOURCE = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});

export default class DriveRoomOne extends Component {
    static propTypes = {
        saveKey: PropTypes.string,
        saveData: PropTypes.object,
    };
    // 构造
    constructor(props) {
        super(props);
        // 初始状态
        this.state = {};
        const {saveData} = this.props;
        if (!saveData.qaDriveRoomOne) {
            saveData.qaDriveRoomOne = Util.defaultGuaranteeDriveRoomOne();
        }
        this._clickedNew = this._clickedNew.bind(this);
    }

    render() {
        const {saveData} = this.props;
        return (
            <View style={{flex: 1}}>
                <ModuleCommonHeader title={'驾驶舱内检查一'}/>
                <ListView
                    dataSource={DATA_SOURCE.cloneWithRows(saveData.qaDriveRoomOne)}
                    renderRow={this._renderRow}/>
                <NextButton onClickedListener={() => this._clickedNew()}/>
            </View>
        );
    }

    _renderRow(item) {
        return <SwitchTextItem object={item} onValue='正常' offValue='不正常'/>
    }

    _clickedNew() {
        const {saveKey, saveData} = this.props;
        Util.saveData(saveKey, saveData);
        Actions.DriveRoomTwo({saveKey, saveData});
    }
}